package tcm.test.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tcm.test.pojo.entity.Product;
import java.util.List;


@Mapper
public interface ProductMapper {
    //添加新商品
    @Insert("insert into products (id, name, price, stock, create_time, update_time) " +
            "VALUES" +
            "(#{id},#{name},#{price},#{stock},#{createTime},#{updateTime})")
    void register(Product p);

    //查询所有商品
    @Select("select count(*)from products")
    Integer count();

    //分页查询所有商品
    @Select("select * from products limit #{arg0},#{arg1}")
    List<Product> getALL(Integer start, Integer size);

    //根据id查询商品
    @Select("select * from products where id=#{id}")
    Product getById(Long id);

    //根据id更新商品
    void update(Product product);

    //根据id删除商品
    @Delete("delete from products where id=#{id}")
    void deleteById(Long id);
}